/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var sumOfLeftLeaves = function(root) {
  let result = 0;
  function preView(node, left) {
    if(!node) return ;
    if(!node.left && !node.right && left) {
      result += node.val;
    }
    if(node.left) preView(node.left, 1);
    if(node.right) preView(node.right, 0);
  }
  preView(root);
  return result;
};
